package com.lzs.bootsafety.common.oss;

import com.lzs.bootsafety.business.oss.entity.SysFile;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
/**
 *  @author  zhanshi Liu
 *  @date    2020/04/20
 *  @website www.jhmsona.cn
 *
 */
public class GlobalFileUpload extends BaseFileUpload implements FileUpload {

    @Override
    public SysFile upload(InputStream file, String suffix, boolean save) {
        FileApi fileApi = getFileApi(null);
        SysFile sysFile = fileApi.uploadFile(file,suffix);
        return saveFile(sysFile,save);
    }

    @Override
    public SysFile upload(File file, boolean save) {
        FileApi fileApi=getFileApi(null);
        SysFile sysFile = fileApi.uploadFile(file);
        return saveFile(sysFile,save);
    }

    @Override
    public SysFile upload(MultipartFile file, boolean save) {
        FileApi fileApi = getFileApi(null);//获取配置信息
        SysFile sysFile = fileApi.uploadFile(file);//获取文件信息
        return saveFile(sysFile,save);
    }

    @Override
    public boolean download(String filePath, String storageType){
        FileApi fileApi = getFileApi(storageType);
        return download(fileApi,filePath,storageType);
    }

    @Override
    public boolean delete(String filePath, String storageType) {
        FileApi fileApi = getFileApi(storageType);
        return delete(fileApi,filePath,storageType);
    }
}
